package com.longxi.tianjintianbao.ui.adapter.multitype.equipment;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.equipment.Equipment;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class EquipmentViewBinder extends ItemViewBinder<Equipment, EquipmentViewBinder.ViewHolder> {

    SelectEquipmentListener listener;
    public EquipmentViewBinder(SelectEquipmentListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_assets2, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Equipment equipment) {
        holder.tvAssName.setText("资产编号:" + equipment.getCode() + "\n资产名称:" + equipment.getName());
        holder.tvAssName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvAssName;
        ViewHolder(View itemView) {
            super(itemView);
            tvAssName = itemView.findViewById(R.id.tvAssName);
        }
    }

    public interface SelectEquipmentListener {
        void onSuccess(int position);
    }

}
